package com.kuangstudy.collection.map;

import java.util.Comparator;
import java.util.TreeMap;

/**
 * ClassName: Demo3
 * date: 2021/07/13 22:22:48
 *
 * @author zlk
 */
public class Demo3 {
    public static void main(String[] args) {
        TreeMap<Student, String> treeMap = new TreeMap<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                int n1 = o1.getName().compareTo(o2.getName());
                int n2 = o1.getAge() - o2.getAge();
                return n1==0?n1:n2;
            }
        });
        Student s1 = new Student("kk",12);
        Student s2 = new Student("kk1",121);
        Student s3 = new Student("kk2",122);
        Student s4 = new Student("kk3",123);
        treeMap.put(s1,"kk");
        treeMap.put(s2,"kk1");
        treeMap.put(s3,"kk2");
        treeMap.put(s4,"kk3");
        treeMap.put(new Student("kk3",123),"kk4");
        System.out.println(treeMap.size());
        System.out.println(treeMap.toString());
        /*删除*/
        treeMap.remove(s3);
        System.out.println(treeMap.size());
    }
}
